package ex01;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/Ex01")
public class Ex01 extends HttpServlet {
	
	private static final long serialVersionUID = 165160604915514115L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		PrintWriter out;
		String parametroNumero = request.getParameter("numero");

		try {
			out = response.getWriter();
			response.setContentType("text/html");

			out.println("<html><body>");

			if (parametroNumero != null) {
				int numero = Integer.parseInt(parametroNumero);
				out.println("<h1>Tabuada de multiplicacao de "
						+ parametroNumero + " </h1>");
				out.println("<table border=\"1\">");
				out.println("<tr>");
				out.println("<th>Valor</th>");
				out.println("<th>X</th>");
				out.println("<th>Resultado</th>");
				out.println("</tr>");
				for (int i = 0; i <= 10; i++) {
					out.println("<tr>");
					out.println("<td>" + parametroNumero + "</td>");
					out.println("<td> X </td>");
					out.println("<td> = " + numero * i + "</td>");
					out.println("</tr>");
				}
				out.println("</table>");
			} else {
				out.println("<h3>Parametro ausente!</h3>");
			}

			out.println("</body></html>");
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
